package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.projeto.sakila.bean.Actor;
import br.com.projeto.sakila.bean.Category;

public class CategoryDao {
	private SessionFactory sessionFactory;
	private Session session;

	public CategoryDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public long buscarCategory(){
		long tempoInicial = System.currentTimeMillis();
		
		List<Category> listaCategory = new ArrayList<>();
		try{
			session = sessionFactory.openSession();
			 
			listaCategory = session.createQuery("from Category").list();
			
			session.close();
		} catch (Exception e){
			System.err.println("Erro no buscar Category");
		}
		
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		
		return tempo;

	}
	
	public void listarCategory(List<Category> lista){
		System.out.println("---------------------------");
		for (Category category : lista) {
			System.out.println("ID : " + category.getId());
			System.out.println("NAME : " + category.getName());
			//TODO: falta filmList
			System.out.println("---------------------------");
		}
	}
}
